<?php

namespace App\Http\Controllers\Shop;

use App\Http\Controllers\ShopController;
use App\Models\Shop\Store;
use Illuminate\Http\Request;

use App\Http\Requests;

class StoreSelectController extends ShopController
{
    public function getIndex()
    {
        //获取
        $store = Store::orderBy('id', 'desc')->get()->keyBy('id');
        $storeID = \Illuminate\Support\Facades\Request::cookie('storeID') ? \Illuminate\Support\Facades\Request::cookie('storeID') : 0;
        return view('shopWx.store-select')->with(['store' => $store, 'storeID' => $storeID]);
    }
    public function getSet(Request $request)
    {
        $storeID = $request->has('id') ? $request->input('id') : '';
        if ($storeID)
        {
            $store = Store::find($storeID);
            if($store)
            {
                return response(json_encode([
                    'code'  =>  '1',
                    'msg'   =>  'success'
                ]))->withCookie(cookie()->forever('storeID', $store->id));
            }
        }
        return response(json_encode([
            'code'  =>  '0',
            'msg'   =>  'error'
        ]));
    }
}
